{include file="public/_meta" /}
<body>
<div class="wrapper">

    {include file="public/_header" /}

    <!-- Sidebar -->
    {include file="public/_menu" /}
    <!-- End Sidebar -->

    <div class="main-panel">

        <div class="content">
            <div class="page-inner">

                <!-- 面包屑 -->
                {include file="public/_page_header" /}

                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-header">
                                <div class="d-flex align-items-center">
                                    <h4 class="card-title">数据表</h4>
                                    <button class="btn btn-primary btn-round ml-auto" data-toggle="modal" data-target="#addRowModal" onClick="add_item(0)">
                                        <i class="fa fa-plus"></i>
                                        添加
                                    </button>

                                </div>
                            </div>
                            <div class="card-body">
                                <!-- Modal -->
                                <div class="modal fade" id="addRowModal" tabindex="-1" role="dialog" aria-hidden="true">
                                    <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                            <div class="modal-header no-bd">
                                                <h5 class="modal-title">
														<span class="fw-mediumbold">添加</span>

                                                </h5>
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                    <span aria-hidden="true">&times;</span>
                                                </button>
                                            </div>
                                            <div class="modal-body">
                                                <form id="form-modal">
                                                    <div class="row">

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="name" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">名称</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="name" name="name" placeholder="名称">
                                                            </div>
                                                        </div>
                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="table_name" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">表名</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="table_name" name="table_name" placeholder="表名">
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="table_name" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">时间类型</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="time_type" name="time_type" placeholder="1时间戳2时间日期">
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="sort" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">备注</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="mark" name="mark" placeholder="备注">
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="sort" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">排序</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="sort" name="sort" placeholder="排序">
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="modal-footer no-bd">
                                                        <input type="hidden" name="id" value="">
                                                        <button type="submit" id="addRowButton" class="btn btn-primary">保存</button>
                                                        <button type="button" class="btn btn-danger" data-dismiss="modal">关闭</button>
                                                    </div>
                                                </form>
                                            </div>

                                        </div>
                                    </div>
                                </div>

                                <div class="modal fade" id="addRowModal4" tabindex="-1" role="dialog" aria-hidden="true">
                                    <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                            <div class="modal-header no-bd">
                                                <h5 class="modal-title">
                                                    <span class="fw-mediumbold">请选择要删除的时段</span>
                                                </h5>
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                    <span aria-hidden="true">&times;</span>
                                                </button>
                                            </div>
                                            <div class="modal-body">
                                                <form id="form-modal4">
                                                    <div class="row">

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="start_time" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">时间 <b class="required_b">*</b> </font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="times" name="times" autocomplete="off" placeholder="时间">
                                                            </div>
                                                        </div>

                                                    </div>
                                                    <div class="modal-footer no-bd">
                                                        <button type="submit" id="addRowButton4" class="btn btn-primary">确定</button>
                                                        <button type="button" class="btn btn-danger" data-dismiss="modal">关闭</button>
                                                    </div>
                                                </form>
                                            </div>

                                        </div>
                                    </div>
                                </div>

                                <div class="table-responsive">
                                    <table id="add-row" class="display table table-striped table-hover" >
                                        <thead>
                                        <tr>
                                            <th><input type="checkbox" class="check">全选</th>
<!--                                            <th>ID</th>-->
                                            <th>名称</th>
                                            <th>表名</th>
                                            <th>备注</th>
                                            <th>排序</th>
                                            <th style="width: 10%">操作</th>
                                        </tr>
                                        </thead>

                                        <tbody>

                                        {volist name="systemLogs" id="vo"}
                                        <tr>
                                            <td><input type="checkbox" class="check" value="{$vo.id}" name="idcheckbox"></td>
<!--                                            <td>{$vo.id}</td>-->
                                            <td>{$vo.name}</td>
                                            <td>{$vo.table_name}</td>
                                            <td>{$vo.mark}</td>
                                            <td>{$vo.sort}</td>
                                            <td>
                                                <div class="form-button-action">

                                                    <button type="button" data-toggle="tooltip" onClick="admin_del(this,'{$vo.id}')" title="" class="btn btn-link btn-danger" data-original-title="删除">
                                                    <i class="fa fa-times"></i>删除
                                                    </button>

                                                </div>



                                            </td>
                                        </tr>
                                        {/volist}

                                        </tbody>
                                    </table>
                                    <div class="layui-box layui-laypage layui-laypage-molv">

                                        <button type="button" title="选择删除时段" class="btn btn-danger layui-btn ml-auto" data-toggle="modal" data-target="#addRowModal4">
                                                                                    <i class="layui-icon"></i>删除数据
                                                                                </button>

                                        <button type="button" title="清除城市备注" class="layui-btn layui-btn-primary layui-border-red" onclick="clearCity()">
                                            清除城市备注
                                        </button>
                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>


            </div>
        </div>

        {include file="public/_footer" /}


    </div>



</div>

{include file="public/_js" /}

</body>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    var SCOPE = {
        'status_url':"{:url('admin/status')}",
        'delete_url':"{:url('system/tableDel')}",
        'clearCity':"{:url('system/clearCity')}",
        'item_url':"{:url('admin/edit')}",
        'add_url':"{:url('system/tableSave')}",
        'db_del':"{:url('system/dbDelete')}"
    };


    $(function(){
        var commitStatus = false;
        /*表单验证*/
        $("#form-modal").validate({
            rules:{
                name:{
                    required:true,
                    minlength:2,
                    maxlength:20
                },
                table_name:{
                    required:true,
                    minlength:2,
                    maxlength:50
                },

            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var url = SCOPE.add_url;
                if(commitStatus==true){
                    return false;
                }
                /*表单提交*/
                $(form).ajaxSubmit({
                    type: 'post',
                    url: url,
                    success: function(data){
                        if(data.code == 1001){
                            commitStatus==true
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000
                            }, function(){
                                parent.location.reload();
                            });
                        }else{
                            layer.msg(data.msg,{icon:2,time:2000});
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg(errorThrown,{icon:2,time:2000});
                    }
                });

            }
        });

        $("#form-modal4").validate({
            rules:{
                times:{
                    required:true
                },

            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var url = SCOPE.db_del;
                if(commitStatus==true){
                    return false;
                }
                var chk_value =[];
                $('input[name="idcheckbox"]:checked').each(function(){ //遍历，将所有选中的值放到数组中
                    chk_value.push($(this).val());
                });
                var loading = layer.load('加载中...', {
                    shade: [0.3,'#fff'] //0.1透明度的白色背景
                });
                /*表单提交*/
                $(form).ajaxSubmit({
                    type: 'post',
                    url: url,
                    data:{id:chk_value},
                    success: function(data){
                        layer.close(loading);
                        if(data.code == 1001){
                            commitStatus = true;
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000
                            }, function(){
                                parent.location.reload();
                            });
                        }else{
                            layer.msg(data.msg,{icon:2,time:2000});
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg(errorThrown,{icon:2,time:2000});
                    }
                });

            }
        });

    });

    function add_item(id) {
        $("input[name='id']").val(id);
        document.getElementById('form-modal').reset();
        $(".fw-mediumbold").text('添加');
        $("input[name='password']").attr('placeholder','初始密码');

    }

    function edit_item(id) {
        $.ajax({
            type: 'GET',
            url: SCOPE.item_url,
            dataType: 'json',
            data: {id:id},
            success: function(res){
                if(res.code == 1001){
                    $(".fw-mediumbold").text('编辑');
                    $("input[name='id']").val(res.data.id);
                    $("input[name='phone']").val(res.data.phone);
                    $("input[name='user_id']").val(res.data.user_id);
                    $("input[name='realname']").val(res.data.realname);
                    $("input[name='password']").attr('placeholder','不修改则不填');
                    $("#group_id").val(res.data.access.group_id);
                    $("#db_type").val(res.data.db_type);
                }else{
                    layer.msg('参数错误',{icon:2,time:2000});
                }

            },
            error:function(res) {
                layer.msg('网络错误,稍后再试...',{icon:2,time:2000});
            }
        });
    }


    /*管理员-删除*/
    function admin_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: 'POST',
                url: SCOPE.delete_url,
                dataType: 'json',
                data: {id:id},
                success: function(data){
                    if(data.code == 1001){
                        $(obj).parents("tr").remove();
                        layer.msg('删除管理员成功!',{icon:1,time:2000});
                    }else{
                        layer.msg(data.msg,{icon:2,time:2000});
                    }

                },
                error:function(data) {
                    layer.msg('网络错误,稍后再试...',{icon:2,time:2000});
                }
            });
        });
    }

    function clearCity(){
        layer.confirm('确认要清除吗？',function(index){
            var loading = layer.load('加载中...', {
                shade: [0.3,'#fff'] //0.1透明度的白色背景
            });
            $.ajax({
                type: 'POST',
                url: SCOPE.clearCity,
                dataType: 'json',
                success: function(data){
                    layer.close(loading);
                    if(data.code == 1001){
                        layer.msg('清除成功!',{icon:1,time:2000});
                    }else{
                        layer.msg(data.msg,{icon:2,time:2000});
                    }

                },
                error:function(data) {
                    layer.msg('网络错误,稍后再试...',{icon:2,time:2000});
                }
            });
        });
    }


    /*管理员-停用*/
    function admin_stop(obj,id){
        layer.confirm('确认要停用吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……
            var url = SCOPE.status_url;
            $.post(url,{status:2,id:id},function(data){
                if(data.code == 1001){
                    layer.msg('已停用!',{icon: 1,time:1000},function(){
                        window.location.reload();
                    });
                }else{
                    layer.msg(data.msg,{icon: 2,time:1000});
                }

            });


        });
    }

    /*管理员-启用*/
    function admin_start(obj,id){
        layer.confirm('确认要启用吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……

            var url = SCOPE.status_url;
            $.post(url,{status:1,id:id},function(data){
                if(data.code == 1001){

                    layer.msg('已启用!',{icon: 1,time:1000},function(){
                        window.location.reload();
                    });
                }else{
                    layer.msg(data.msg,{icon: 2,time:1000});
                }
            });
        });
    }

    laydate.render({
        elem: '#times'
        ,type: 'datetime'
        ,range: true
    });

</script>
</html>




























